﻿using Newtonsoft.Json;
using System.Text;
using System.IO;
using System;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.Reflection;
using AFI.Speargun.Web.Core;

namespace AFI.Speargun.Web.Models
{
    public partial class Category : IHierarchical<Category>
    {
        public Guid Id
        {
            get { return this.CategoryId; }
            set { this.CategoryId = value; }
        }

        public AssetEntryAdditionalDefinitionSchema AssetEntryAdditionalDefinitionSchema
        {
            get
            {
                AssetEntryAdditionalDefinitionSchema assetEntryAdditionalDefinition;

                if (String.IsNullOrEmpty(this.AssetEntryAdditionalDefinition))
                {
                    assetEntryAdditionalDefinition = new AssetEntryAdditionalDefinitionSchema();
                    assetEntryAdditionalDefinition.LoadProperties();
                }
                else
                {
                    using (StringReader reader = new StringReader(this.AssetEntryAdditionalDefinition))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AssetEntryAdditionalDefinitionSchema));
                        assetEntryAdditionalDefinition = (AssetEntryAdditionalDefinitionSchema)serializer.Deserialize(reader);
                    }
                }

                return assetEntryAdditionalDefinition;
            }

            set
            {
                StringBuilder sb = new StringBuilder();
                using (StringWriter writer = new StringWriter(sb))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(AssetEntryAdditionalDefinitionSchema));
                    serializer.Serialize(writer, value);
                }

                this.AssetEntryAdditionalDefinition = sb.ToString();
            }
        }
    }
}
